




/*
'===============================================================================
'  HNG.Portal.BL.TblStatsManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblStatsManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_StatTypeId="StatTypeId";
				
				public const String Field_Count="Count";
				
				public const String Field_Time="Time";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblStatsManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_StatTypeId,typeof(int));
			
						
			
			dt.Columns.Add(Field_Count,typeof(float));
			
						
			
			dt.Columns.Add(Field_Time,typeof(DateTime));
			
			            
            return dt;			
		}
			
		public TblStatsEntity Convert_Entity(TblStatsEntity _TblStatsEntity,TblStatsEntity _TblStatsEntity_XML)
		{	
			
				
			_TblStatsEntity.Id= _TblStatsEntity_XML.Id;
				
			_TblStatsEntity.StatTypeId= _TblStatsEntity_XML.StatTypeId;
				
			_TblStatsEntity.Count= _TblStatsEntity_XML.Count;
				
			_TblStatsEntity.Time= _TblStatsEntity_XML.Time;
				
			
			return _TblStatsEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblStatsEntity Insert(TblStatsEntity TblStatsEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblStatsEntity, true);
			}
			return TblStatsEntity;
		}

		
		public TblStatsEntity Insert(int Id, int StatTypeId, float Count, DateTime Time)
		{
			TblStatsEntity _TblStatsEntity = new TblStatsEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblStatsEntity.Id = Id;
				_TblStatsEntity.StatTypeId = StatTypeId;
				_TblStatsEntity.Count = Count;
				_TblStatsEntity.Time = Time;
				adapter.SaveEntity(_TblStatsEntity, true);
			}
			return _TblStatsEntity;
		}

		public TblStatsEntity Insert(int StatTypeId, float Count, DateTime Time)
		{
			TblStatsEntity _TblStatsEntity = new TblStatsEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblStatsEntity.StatTypeId = StatTypeId;
				_TblStatsEntity.Count = Count;
				_TblStatsEntity.Time = Time;
				adapter.SaveEntity(_TblStatsEntity, true);
			}
			return _TblStatsEntity;
		}

		public bool Update(TblStatsEntity _TblStatsEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblStatsFields.Id == _TblStatsEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblStatsEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblStatsEntity _TblStatsEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblStatsEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int StatTypeId, float Count, DateTime Time)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblStatsEntity _TblStatsEntity = new TblStatsEntity(Id);
				if (adapter.FetchEntity(_TblStatsEntity))
				{
				
					_TblStatsEntity.StatTypeId = StatTypeId;
					_TblStatsEntity.Count = Count;
					_TblStatsEntity.Time = Time;
					adapter.SaveEntity(_TblStatsEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblStatsEntity _TblStatsEntity = new TblStatsEntity(Id);
				if (adapter.FetchEntity(_TblStatsEntity))
				{
					adapter.DeleteEntity(_TblStatsEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblStatsEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblStatsEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByStatTypeId(int StatTypeId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.StatTypeId == StatTypeId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblStatsEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCount(float Count)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Count == Count);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblStatsEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTime(DateTime Time)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Time == Time);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblStatsEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblStatsEntity SelectOne(int Id)
		{
			TblStatsEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblStatsEntity _TblStatsEntity = new TblStatsEntity(Id);
				if (adapter.FetchEntity(_TblStatsEntity))
				{
					toReturn = _TblStatsEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblStatsCollection = new EntityCollection( new TblStatsEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsCollection, null, 0, null);
			}
			return _TblStatsCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsCollection, filter, 0, null);
			}
			return _TblStatsCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByStatTypeId(int StatTypeId)
		{
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.StatTypeId == StatTypeId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsCollection, filter, 0, null);
			}
			return _TblStatsCollection;
		}
		
		// Return DataTable
		public DataTable SelectByStatTypeIdRDT(int StatTypeId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.StatTypeId == StatTypeId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByCount(float Count)
		{
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Count == Count);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsCollection, filter, 0, null);
			}
			return _TblStatsCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCountRDT(float Count)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Count == Count);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTime(DateTime Time)
		{
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Time == Time);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblStatsCollection, filter, 0, null);
			}
			return _TblStatsCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTimeRDT(DateTime Time)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblStatsCollection = new EntityCollection(new TblStatsEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblStatsFields.Time == Time);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblStatsCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
